using System;
using System.Xml;

namespace FreeFlow.Client
{
	/// <summary>
	/// An image field.
	/// </summary>
	[Serializable]
	public class ImageField : Field
 	{
    private IGetAttachment getAttachment;
    internal ImageField(Form form, XmlElement fieldNode, IGetAttachment getAttachment)
      : base(form, fieldNode)
		{
      if (fieldNode != null)
        file = fieldNode.GetAttribute("File");
      this.getAttachment = getAttachment;
		}

    internal override bool ShouldAddToFieldInput()
    {
      return false;
    }

    private string file;
    /// <summary>
    /// Gets the file name of the image.
    /// </summary>
    public string File
    {
      get
      {
        return file;
      }
    }

    private byte[] image;
    /// <summary>
    /// Gets the image binary data.
    /// </summary>
    public byte[] Image
    {
      get
      {
        if (image == null)
        {
          // get from server
          if (getAttachment != null)
            image = getAttachment.GetAttachment(AttachmentType.Procedure, file, Form.Procedure);
        }
        return image;
      }
    }
	}
}
